/**
 * 用于处理异常的http返回
 */
import store from '../store/index'

export const handleFailResp = function (context, resp) {
    switch (resp.statusCode) {
        case 2001:
            context.$confirm('用户未登录或登录已超时', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'info'
            }).then(() => {
                store.commit('logout')
                context.$router.push({ name: 'Login' })
            }).catch(() => {
            });
            break
        case 3001:
            context.$confirm(resp.message, '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
            }).catch(() => {
            });
            break
        case 1001:
            context.$confirm(resp.message, '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
            }).catch(() => {
            });
            break
        default:
            context.$message({
                type: 'error',
                message: resp.message
            });
    }
}